/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * CadastroModelo.java
 *
 * Created on 26/01/2010, 16:35:13
 */
package br.com.sofp.Visao;

import java.awt.Component;
import java.awt.Dimension;
import javax.swing.ComboBoxModel;
import javax.swing.DefaultListModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.tree.DefaultMutableTreeNode;


/**
 *
 * @author Daniel
 */
public class CadastroModelo extends javax.swing.JInternalFrame {

    /** Creates new form CadastroModelo */
    public CadastroModelo() {
        initComponents();
        jtabpanel.setSelectedIndex(0);
        ConfiguraFormulario("CADASTRO DE XXXXX");
    }
    DefaultMutableTreeNode pai;

    private void ConfiguraFormulario(String TituloForm) {
        // Seta ao título do fomulário
        this.setTitle(TituloForm);
        // Captura o tamanho do formulário
        Dimension tamnhoForm = this.getSize();
        // Captura a resolução da Tela
        Dimension screenSize = this.getToolkit().getScreenSize();
        // Centraliza o formulário na Tela
        this.setLocation((screenSize.width - tamnhoForm.width) / 2,
                (screenSize.height - tamnhoForm.height - 180) / 2);

    }

    private void ConfigurarNavegacao() {
        // Configura o menu de Navegação
        //DefaultMutableTreeNode pai = new DefaultMutableTreeNode("SisCom");
        pai = new DefaultMutableTreeNode("Menu de Opções");
        DefaultMutableTreeNode filho1 = new DefaultMutableTreeNode("Consulta");
        DefaultMutableTreeNode filho2 = new DefaultMutableTreeNode("Manutenção");
        DefaultMutableTreeNode filho3 = new DefaultMutableTreeNode("Sair");
        pai.add(filho1);
        pai.add(filho2);
        pai.add(filho3);
        //jtMenu =  new javax.swing.JTree(pai);
    }

    private void BotoesPadrao() {
        jbNovo.setEnabled(false);
        jbAlterar.setEnabled(false);
        jbCancelar.setEnabled(false);
        jbSalvar.setEnabled(false);
        jbExcluir.setEnabled(false);
        jbImprimir.setEnabled(false);
        jbExportar.setEnabled(false);
    }

    private void DesabilitaMenu() {
        jtMenu.setEnabled(false);
    }

    private void HabilitaMenu() {
        jtMenu.setEnabled(true);

    }

    private void Novo() {
        DesabilitaMenu();
        jbNovo.setEnabled(false);
        jbCancelar.setEnabled(true);
        jbSalvar.setEnabled(true);
    }

    private void Cancelar() {
        HabilitaMenu();
        BotoesPadrao();
    }

    private void Salvar() {
        HabilitaMenu();
        BotoesPadrao();
    }

    private void Alterar() {
    }

    private void Excluir() {
    }

    private void gravar() {
    }

    private void danielVarrerPanel() {

        for (int i = 0; i < jtBotoes.getComponentCount(); i++) {
            Component comp = jtBotoes.getComponent(i);

            if (comp instanceof JButton) {
                JButton bt = (JButton) comp;
                if (bt.getName() == "1") {
                    JOptionPane.showMessageDialog(null, bt.getText());
                }

            }
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jpPrincipal = new javax.swing.JPanel();
        jpSecundario = new javax.swing.JPanel();
        jpForms = new javax.swing.JPanel();
        jpEscondeAbas = new javax.swing.JPanel();
        jtabpanel = new javax.swing.JTabbedPane();
        jpConsulta = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jtblConsulta = new javax.swing.JTable();
        jpPesquisaConsulta = new javax.swing.JPanel();
        jcomboColunas = new javax.swing.JComboBox();
        jLabel2 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jFormattedTextField1 = new javax.swing.JFormattedTextField();
        jbPesquisar = new javax.swing.JButton();
        jpManutencao = new javax.swing.JPanel();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        pnMenu = new javax.swing.JPanel();
        jtBotoes = new javax.swing.JPanel();
        jbNovo = new javax.swing.JButton();
        jbSalvar = new javax.swing.JButton();
        jbCancelar = new javax.swing.JButton();
        jbExcluir = new javax.swing.JButton();
        jbAlterar = new javax.swing.JButton();
        jbImprimir = new javax.swing.JButton();
        jbExportar = new javax.swing.JButton();
        jtArvore = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        ConfigurarNavegacao();
        jtMenu = new javax.swing.JTree(pai);

        setClosable(true);
        setIconifiable(true);

        jpPrincipal.setBackground(new java.awt.Color(102, 255, 102));

        jpSecundario.setBackground(new java.awt.Color(255, 255, 255));
        jpSecundario.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jpSecundario.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jpForms.setBackground(new java.awt.Color(255, 255, 255));

        jpEscondeAbas.setBackground(new java.awt.Color(255, 255, 255));
        jpEscondeAbas.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jtabpanel.setBackground(new java.awt.Color(255, 255, 255));
        jtabpanel.setForeground(new java.awt.Color(255, 255, 255));
        jtabpanel.setTabPlacement(javax.swing.JTabbedPane.BOTTOM);

        jpConsulta.setBackground(new java.awt.Color(255, 255, 255));
        jpConsulta.setBorder(javax.swing.BorderFactory.createTitledBorder("Consulta de Dados"));
        jpConsulta.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jtblConsulta.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null},
                {null},
                {null},
                {null}
            },
            new String [] {
                "Título 1"
            }
        ));
        jScrollPane2.setViewportView(jtblConsulta);

        jpConsulta.add(jScrollPane2, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 110, 545, 230));

        jpPesquisaConsulta.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
        jpPesquisaConsulta.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jcomboColunas.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Razão Social", "Nome Cliente" }));
        jpPesquisaConsulta.add(jcomboColunas, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 30, 150, -1));

        jLabel2.setText("Informação a Pesquisar");
        jpPesquisaConsulta.add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 10, -1, -1));

        jLabel1.setText("Informação a Pesquisar");
        jpPesquisaConsulta.add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(170, 10, -1, -1));
        jpPesquisaConsulta.add(jFormattedTextField1, new org.netbeans.lib.awtextra.AbsoluteConstraints(170, 30, 250, -1));

        jbPesquisar.setFont(new java.awt.Font("Tahoma", 0, 10)); // NOI18N
        jbPesquisar.setText("Pesquisar");
        jbPesquisar.setHorizontalAlignment(javax.swing.SwingConstants.LEADING);
        jbPesquisar.setIconTextGap(1);
        jbPesquisar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbPesquisarActionPerformed(evt);
            }
        });
        jpPesquisaConsulta.add(jbPesquisar, new org.netbeans.lib.awtextra.AbsoluteConstraints(430, 27, 100, -1));

        jpConsulta.add(jpPesquisaConsulta, new org.netbeans.lib.awtextra.AbsoluteConstraints(11, 30, 547, 70));

        jtabpanel.addTab("", jpConsulta);

        jpManutencao.setBackground(new java.awt.Color(255, 255, 255));
        jpManutencao.setBorder(javax.swing.BorderFactory.createTitledBorder(" Manutenção de Dados"));
        jpManutencao.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jTabbedPane1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
        jTabbedPane1.addTab("Dadas Pessoais", jPanel1);

        jPanel2.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
        jTabbedPane1.addTab("Endereço", jPanel2);

        jpManutencao.add(jTabbedPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 70, 340, 190));

        jtabpanel.addTab("", jpManutencao);

        jpEscondeAbas.add(jtabpanel, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 570, 380));

        javax.swing.GroupLayout jpFormsLayout = new javax.swing.GroupLayout(jpForms);
        jpForms.setLayout(jpFormsLayout);
        jpFormsLayout.setHorizontalGroup(
            jpFormsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jpEscondeAbas, javax.swing.GroupLayout.DEFAULT_SIZE, 572, Short.MAX_VALUE)
        );
        jpFormsLayout.setVerticalGroup(
            jpFormsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpFormsLayout.createSequentialGroup()
                .addComponent(jpEscondeAbas, javax.swing.GroupLayout.PREFERRED_SIZE, 350, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jpSecundario.add(jpForms, new org.netbeans.lib.awtextra.AbsoluteConstraints(165, 10, -1, 360));

        pnMenu.setBackground(new java.awt.Color(204, 255, 204));
        pnMenu.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        pnMenu.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jtBotoes.setBackground(new java.awt.Color(204, 255, 204));
        jtBotoes.setBorder(javax.swing.BorderFactory.createTitledBorder(null, " Controles ", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION));
        jtBotoes.setAlignmentX(0.0F);
        jtBotoes.setFont(new java.awt.Font("Tahoma", 0, 11));
        jtBotoes.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jbNovo.setFont(new java.awt.Font("Tahoma", 0, 10)); // NOI18N
        jbNovo.setText("Novo");
        jbNovo.setEnabled(false);
        jbNovo.setFocusable(false);
        jbNovo.setHorizontalAlignment(javax.swing.SwingConstants.LEADING);
        jbNovo.setName("1"); // NOI18N
        jbNovo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbNovoActionPerformed(evt);
            }
        });
        jtBotoes.add(jbNovo, new org.netbeans.lib.awtextra.AbsoluteConstraints(18, 30, 95, -1));

        jbSalvar.setFont(new java.awt.Font("Tahoma", 0, 10));
        jbSalvar.setText("Salvar");
        jbSalvar.setEnabled(false);
        jbSalvar.setHorizontalAlignment(javax.swing.SwingConstants.LEADING);
        jbSalvar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbSalvarActionPerformed(evt);
            }
        });
        jtBotoes.add(jbSalvar, new org.netbeans.lib.awtextra.AbsoluteConstraints(18, 90, 95, -1));

        jbCancelar.setFont(new java.awt.Font("Tahoma", 0, 10));
        jbCancelar.setText("Cancelar");
        jbCancelar.setEnabled(false);
        jbCancelar.setHorizontalAlignment(javax.swing.SwingConstants.LEADING);
        jbCancelar.setName("1"); // NOI18N
        jbCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbCancelarActionPerformed(evt);
            }
        });
        jtBotoes.add(jbCancelar, new org.netbeans.lib.awtextra.AbsoluteConstraints(18, 120, 95, -1));

        jbExcluir.setFont(new java.awt.Font("Tahoma", 0, 10));
        jbExcluir.setText("Excluir");
        jbExcluir.setEnabled(false);
        jbExcluir.setHorizontalAlignment(javax.swing.SwingConstants.LEADING);
        jtBotoes.add(jbExcluir, new org.netbeans.lib.awtextra.AbsoluteConstraints(18, 150, 95, -1));

        jbAlterar.setFont(new java.awt.Font("Tahoma", 0, 10)); // NOI18N
        jbAlterar.setText("Alterar");
        jbAlterar.setEnabled(false);
        jbAlterar.setHorizontalAlignment(javax.swing.SwingConstants.LEADING);
        jtBotoes.add(jbAlterar, new org.netbeans.lib.awtextra.AbsoluteConstraints(18, 60, 95, -1));

        jbImprimir.setFont(new java.awt.Font("Tahoma", 0, 10));
        jbImprimir.setText("Imprimir");
        jbImprimir.setEnabled(false);
        jbImprimir.setHorizontalAlignment(javax.swing.SwingConstants.LEADING);
        jtBotoes.add(jbImprimir, new org.netbeans.lib.awtextra.AbsoluteConstraints(18, 180, 95, -1));

        jbExportar.setFont(new java.awt.Font("Tahoma", 0, 10)); // NOI18N
        jbExportar.setText("Exportar");
        jbExportar.setEnabled(false);
        jbExportar.setHorizontalAlignment(javax.swing.SwingConstants.LEADING);
        jtBotoes.add(jbExportar, new org.netbeans.lib.awtextra.AbsoluteConstraints(18, 210, 95, -1));

        pnMenu.add(jtBotoes, new org.netbeans.lib.awtextra.AbsoluteConstraints(13, 100, 130, 250));

        jtArvore.setBackground(new java.awt.Color(204, 255, 204));
        jtArvore.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jScrollPane1.setBorder(null);

        jtMenu.setBackground(new java.awt.Color(204, 255, 204));
        jtMenu.setFont(new java.awt.Font("Tahoma", 0, 11));
        jtMenu.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                MouseAdapter(evt);
            }
        });
        jScrollPane1.setViewportView(jtMenu);

        jtArvore.add(jScrollPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 150, 86));

        pnMenu.add(jtArvore, new org.netbeans.lib.awtextra.AbsoluteConstraints(1, 1, 150, 90));

        jpSecundario.add(pnMenu, new org.netbeans.lib.awtextra.AbsoluteConstraints(1, 1, 160, 390));

        javax.swing.GroupLayout jpPrincipalLayout = new javax.swing.GroupLayout(jpPrincipal);
        jpPrincipal.setLayout(jpPrincipalLayout);
        jpPrincipalLayout.setHorizontalGroup(
            jpPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jpSecundario, javax.swing.GroupLayout.DEFAULT_SIZE, 745, Short.MAX_VALUE)
        );
        jpPrincipalLayout.setVerticalGroup(
            jpPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jpSecundario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jpPrincipal, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jpPrincipal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void MouseAdapter(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_MouseAdapter

        String selecionado;
        if (jtMenu.getSelectionPath() != null) {
            if (evt.getClickCount() == 2) {
                selecionado = jtMenu.getLastSelectedPathComponent().toString();
                if (selecionado.equals("Consulta")) {
                    HabilitaMenu();
                    BotoesPadrao();
                    jtabpanel.setSelectedIndex(0);

                } else if (selecionado.equals("Manutenção")) {
                    BotoesPadrao();
                    jbNovo.setEnabled(true);
                    jtabpanel.setSelectedIndex(1);


                } else if (selecionado.equals("Sair")) {
                    dispose();
                }
            }
        } else {
            // JOptionPane.showMessageDialog(null, "Quantidade de clicks " + evt.getClickCount());
        }
    }//GEN-LAST:event_MouseAdapter

    private void jbNovoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbNovoActionPerformed
        Novo();
    }//GEN-LAST:event_jbNovoActionPerformed

    private void jbCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbCancelarActionPerformed
        Cancelar();
    }//GEN-LAST:event_jbCancelarActionPerformed

    private void jbSalvarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbSalvarActionPerformed
        Salvar();
    }//GEN-LAST:event_jbSalvarActionPerformed

    private void jbPesquisarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbPesquisarActionPerformed

        DefaultListModel data = new DefaultListModel();
        data.addElement("um");
        data.addElement("dois");
        data.addElement("três");
        data.addElement("quatro");
        data.addElement("cinco");
        JList lista = new JList(data);

        jcomboColunas.removeAllItems();
        //lista.setModel(jcomboColunas.getModel());
        
      //JOptionPane.showMessageDialog(null, lista.getModel().getSize());
        for (int i = 0; i < lista.getModel().getSize(); i++){
         lista.setSelectedIndex(i);
         jcomboColunas.addItem(lista.getSelectedValue());
         
        }


    }//GEN-LAST:event_jbPesquisarActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JFormattedTextField jFormattedTextField1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JButton jbAlterar;
    private javax.swing.JButton jbCancelar;
    private javax.swing.JButton jbExcluir;
    private javax.swing.JButton jbExportar;
    private javax.swing.JButton jbImprimir;
    private javax.swing.JButton jbNovo;
    private javax.swing.JButton jbPesquisar;
    private javax.swing.JButton jbSalvar;
    private javax.swing.JComboBox jcomboColunas;
    private javax.swing.JPanel jpConsulta;
    private javax.swing.JPanel jpEscondeAbas;
    private javax.swing.JPanel jpForms;
    private javax.swing.JPanel jpManutencao;
    private javax.swing.JPanel jpPesquisaConsulta;
    private javax.swing.JPanel jpPrincipal;
    private javax.swing.JPanel jpSecundario;
    private javax.swing.JPanel jtArvore;
    private javax.swing.JPanel jtBotoes;
    private javax.swing.JTree jtMenu;
    private javax.swing.JTabbedPane jtabpanel;
    private javax.swing.JTable jtblConsulta;
    private javax.swing.JPanel pnMenu;
    // End of variables declaration//GEN-END:variables
}
